# Copyright 2022 The IREE Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

################################################################################
#                                                                              #
# E2E Test Artifacts Suite                                                     #
#                                                                              #
# Includes the generated cmake files to build the e2e test artifacts.          #
# The cmake files "generated_*.cmake" are generated by the python script:      #
# "build_tools/testing/generate_cmake_e2e_test_artifacts_suite.py" and sould   #
# not be edited manually. Please read README.md for the instructions to update #
# the test artifacts.                                                          #
#                                                                              #
################################################################################

if(NOT IREE_BUILD_E2E_TEST_ARTIFACTS)
  return()
endif()

################################################################################
# Defines the required variables.                                              #
################################################################################
iree_package_name(PACKAGE_NAME)
set(ROOT_ARTIFACTS_DIR "${IREE_BINARY_DIR}/e2e_test_artifacts")

################################################################################
# Defines the benchmark suite targets                                          #
#                                                                              #
# iree-benchmark-suites* fully prepares benchmark models for benchmarking:     #
#   * importing from source formats to IREE-compatible .mlir files             #
#   * compiling from .mlir files to benchmark-ready .vmfb files                #
#                                                                              #
# Each benchmark preset has a corresponding target                             #
# `iree-benchmark-suites-<preset>`. The full preset list can be found in:      #
# build_tools/python/benchmark_suites/iree/benchmark_presets.py                #
#                                                                              #
################################################################################

# Size-based execution benchmark preset targets.
add_custom_target(iree-benchmark-suites-default)
add_custom_target(iree-benchmark-suites-large)

# Architecture-based execution benchmark preset targets.
add_custom_target(iree-benchmark-suites-android-cpu)
add_custom_target(iree-benchmark-suites-android-cpu-dt-only)
add_custom_target(iree-benchmark-suites-android-gpu)
add_custom_target(iree-benchmark-suites-cuda)
add_custom_target(iree-benchmark-suites-cuda-large)
add_custom_target(iree-benchmark-suites-riscv)
add_custom_target(iree-benchmark-suites-vulkan-nvidia)
add_custom_target(iree-benchmark-suites-x86_64)
add_custom_target(iree-benchmark-suites-x86_64-dt-only)
add_custom_target(iree-benchmark-suites-x86_64-large)

# Compilation benchmark preset targets.
add_custom_target(iree-benchmark-suites-comp-stats)
add_custom_target(iree-benchmark-suites-comp-stats-large)

# iree-e2e-test-artifacts builds all e2e test artifacts.
add_custom_target(iree-e2e-test-artifacts)
add_dependencies(iree-e2e-test-artifacts
  iree-benchmark-suites-default
  iree-benchmark-suites-large
  iree-benchmark-suites-comp-stats
  iree-benchmark-suites-comp-stats-large
)

# Map the legacy, intuitive target to default benchmark preset.
add_custom_target(iree-benchmark-suites)
add_dependencies(iree-benchmark-suites
  iree-benchmark-suites-default
)

# iree-benchmark-import-models* imports benchmark models from their source
# formats, such as .tflite flatbuffers, to IREE-compatible .mlir files.

# Imported models used in iree-benchmark-suites-default + iree-benchmark-suites-comp-stats-default
add_custom_target(iree-benchmark-import-models)
# Imported models used in iree-benchmark-suites-large + iree-benchmark-suites-comp-stats-large
add_custom_target(iree-benchmark-import-models-large)

# Import the generated benchmark suite cmake files.
include(generated_e2e_test_fetch_models.cmake)

include(generated_e2e_test_iree_artifacts.cmake)
